package com.cgtong.android.mvp.presenter;

import com.cgtong.android.bean.ActivityBean;
import com.cgtong.android.bean.BannerBean;
import com.cgtong.android.bean.NewsBean;
import com.cgtong.android.mvp.contract.HomeContract;
import com.cgtong.android.mvp.model.HomeModel;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.exception.ApiException;

import java.util.List;

/**
 * Created by Sky.Bing on 2017/10/24.
 */

public class HomePresenter implements HomeContract.Presenter {
    private HomeContract.View mView;
    private HomeContract.Model mModel;

    public HomePresenter(HomeContract.View view) {
        mView = view;
        mModel = new HomeModel();
    }

    @Override
    public void getActivities() {
        mModel.getActivities(new SimpleCallBack<List<List<ActivityBean>>>() {
            @Override
            public void onError(ApiException e) {
                mView.showActivitiesError();
            }

            @Override
            public void onSuccess(List<List<ActivityBean>> activityBeanLists) {
                mView.showActivities(ActivityBean.parseJsonOfDoubleList(activityBeanLists));
            }
        });
    }

    @Override
    public void getHotNews() {
        mModel.getHotNews(new SimpleCallBack<List<NewsBean>>() {
            @Override
            public void onError(ApiException e) {
                mView.showHotNewsError();
            }

            @Override
            public void onSuccess(List<NewsBean> newsBeanList) {
                mView.showHotNews(newsBeanList);
            }
        });
    }

    @Override
    public void getBannerList() {
        mModel.getBannerList(new SimpleCallBack<List<BannerBean>>() {
            @Override
            public void onError(ApiException e) {
            }

            @Override
            public void onSuccess(List<BannerBean> bannerBeen) {
                mView.showBanner(bannerBeen);
            }
        });
    }
}